package com.jxt.myjxtmanager.views.updateAvatar;


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.media.ExifInterface;
import android.widget.Toast;

import java.io.IOException;

/**
 * 寮瑰�烘��绀哄伐���
 * @author liqq
 *
 */
public final class ImageTool {

	public static void show(Context cx, String msg) {
		Toast.makeText(cx, msg, Toast.LENGTH_SHORT).show();
	}

	public static void show(Context cx, int resId) {
		Toast.makeText(cx, resId, Toast.LENGTH_SHORT).show();
	}
	/**
	 * ��ゆ����х�������瑰��锛���瑰��涓�瀵瑰��姝�
	 * @param bitmap
	 * @param imgpath
	 * @param adjustOritation
	 * @return
	 */
	 public static Bitmap changeDirectionBitmap(Bitmap bitmap ,String imgpath, boolean adjustOritation) {
       	Bitmap bm = bitmap;
         int digree = 0;  
         ExifInterface exif = null;
         try {  
             exif = new ExifInterface(imgpath);
         } catch (IOException e) {
             e.printStackTrace();  
             exif = null;  
         }  
         if (exif != null) {  
             // 璇诲����剧��涓���告�烘�瑰��淇℃��  
             int ori = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                     ExifInterface.ORIENTATION_UNDEFINED);
             // 璁＄�����杞�瑙�搴�  
             switch (ori) {  
             case ExifInterface.ORIENTATION_ROTATE_90:
                 digree = 90;  
                 break;  
             case ExifInterface.ORIENTATION_ROTATE_180:
                 digree = 180;  
                 break;  
             case ExifInterface.ORIENTATION_ROTATE_270:
                 digree = 270;  
                 break;  
             default:  
                 digree = 0;  
                 break;  
             }  
         }  
         if (digree != 0) {  
             // ���杞���剧��  
             Matrix m = new Matrix();
             m.postRotate(digree);  
             bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
                     bm.getHeight(), m, true);  
         }  
         return bm;  
     }  
}